#pragma once
#include "HashTable.h"

namespace Aron
{
	template<class K, class Hash = HashFunc<K>>
	class unordered_set
	{
		struct SetKeyOfT
		{
			const K& operator()(const K& key)
			{
				return key;
			}
		};

	public:
		typedef typename hash_bucket::HashTable<K, const K, SetKeyOfT, Hash>::iterator iterator;

		iterator begin()
		{
			return _ht.begin();
		}

		iterator end()
		{
			return _ht.end();
		}


		pair<iterator, bool> insert(const K& key)
		{
			return _ht.Insert(key);
		}

		unordered_set()
			: _ht()
		{}

		template<class InputIterator>
		unordered_set(InputIterator first, InputIterator last)
			: _ht()
		{
			while (first != last)
			{
				insert(*first);
				++first;
			}
		}

	private:
		hash_bucket::HashTable<K, const K, SetKeyOfT, Hash> _ht;
	};

	void test_set1()
	{
		unordered_set<int> us;
		us.insert(3);
		us.insert(1);
		us.insert(5);
		us.insert(15);
		us.insert(45);
		us.insert(7);

		unordered_set<int>::iterator it = us.begin();
		while (it != us.end())
		{
			//*it += 100;
			cout << *it << " ";
			++it;
		}
		cout << endl;

		for (auto e : us)
		{
			cout << e << " ";
		}
		cout << endl;
	}

	void test_set2()
	{
		vector<int> arr = { 7,3,6,9,3,1,6,2 };
		unordered_set<int> s1(arr.begin(), arr.end());

		auto it = s1.begin();
		//*it = 668;

		for (auto e : s1)
			cout << e << " ";
		cout << endl;
	}

	void test_set3()
	{
		unordered_set<int> s1;
		auto ret = s1.insert(1);
		cout << "<" << *ret.first << ">" << " | " << ret.second << endl;

		ret = s1.insert(1);
		cout << "<" << *ret.first << ">" << " | " << ret.second << endl;
	}

}
